package com.iss.ljx.duty.controller;

import com.iss.ljx.duty.entity.SearchDutyEntity;
import com.iss.ljx.duty.service.DutyService;
import com.iss.ljx.mybatis.entity.PtDutyEntity;
import com.iss.ljx.mybatis.entity.PtRoleEntity;
import com.iss.ljx.mybatis.flexigrid.PadingRstType;
import com.iss.ljx.mybatis.flexigrid.PagingBean;
import com.iss.ljx.mybatis.ztree.ZtreeEntity;
import com.iss.ljx.spring.controller.BaseController;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName DutyController
 * @Description TODO
 * @Author Yubuer
 * @Date 2022/5/16 19:03
 * @Version 1.0
 **/
@Controller
@RequestMapping("/duty")
public class DutyController extends BaseController {
    private Logger logger = LogManager.getLogger(this.getClass());
    @Resource
    private DutyService dutyService;

    @Secured("ROLE_gqgy_data_role")
    @RequestMapping("/dutyPage")
    public String dutyPage(){
        return "duty/dutyPage";
    }
    @Secured("ROLE_gqgy_data_role")
    @RequestMapping("/queryDutyListPage")
    @ResponseBody
    public PadingRstType<PtDutyEntity> queryDutyListPage(SearchDutyEntity search, PagingBean paging){
        logger.info(search);
        logger.info(paging);
        PadingRstType<PtDutyEntity> ptDutyEntityPadingRstType = dutyService.queryDutyListPage(search,paging);
        return ptDutyEntityPadingRstType;
    }

    @Secured("ROLE_gqgy_data_role")
    @RequestMapping("/getMenuTree")
    @ResponseBody
    public List<ZtreeEntity> getMenuTree(){
        return dutyService.getMenuTree();
    }

    @RequestMapping("/dutyAdd")
    @ResponseBody
    public String dutyAdd(PtDutyEntity ptDutyEntity){
        dutyService.dutyAdd(ptDutyEntity);
        return getSuccessMsg("duty.add.success");
    }
    @RequestMapping("/dutyDelete")
    @ResponseBody
    public String roleDelete(String dutyId){
        dutyService.dutyDelete(dutyId);
        return getSuccessMsg("duty.del.success");
    }
    @RequestMapping("/dutyUpdate")
    @ResponseBody
    public String roleUpdate(PtDutyEntity ptDutyEntity){
        dutyService.dutyUpdate(ptDutyEntity);
        return getSuccessMsg("duty.update.success");
    }


}
